package com.zy.servlet.marks;

import java.io.IOException;
import java.util.List;
import com.zy.entity.Mark;
import com.google.gson.Gson;
import com.zy.service.GetCarService;
import com.zy.service.GetMarksService;
import com.zy.service.impl.GetMarksServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/getMarks")
public class GetMarksServlet extends HttpServlet {
    private GetMarksService addMarksService = new GetMarksServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = 5;
        int offset = (page - 1) * limit;
        List<Mark> marks = addMarksService.getMarks(offset, limit);
        String json = new Gson().toJson(marks);
        response.setContentType("application/json");
        response.getWriter().write(json);
}

}